Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Types after preact 10.25 #1803

Merged
merged 7 commits into from
Dec 2, 2024

Conversation

rschristian
Copy link
Contributor

@rschristian rschristian commented Nov 29, 2024

My attempt to help out with #1797

The new per-element type interfaces introduces in Preact 10.25 should provide better type assistance but does require a switch over. Additionally, whilst I'm not familiar with this code base I stumbled upon what looks like docs while grepping through; I took the opportunity to update those (seemingly) accordingly?

There have been a few attribute fixes upstream already since 10.25, but not yet released. This PR is therefore a result of manually copying over the type changes since to see if there are any issues we hadn't yet caught. As such, this is based on an in-progress 10.25.1, not really 10.25.0.

There's a few issues remaining:

  • src/components/icons/SpinnerCircle.tsx: Property type does not exist...
    • Upstream issue, was missing on the interface. Will get that corrected FIXED, will go out in next version
  • src/pattern-library/components/patterns/navigation/LinkButtonPage.tsx: Property href does not exist...
    • This error seems correct? Very unfamiliar with the code, but it does appear like you're trying to pass href to a button
  • src/components/input/Checkbox.tsx: Property call does not exist...
    • This one's a bit weirder and I need some time with yet. I'm not quite sure what's going wrong, but I'd assume it's an upstream issue with our types. FIXED, will also go out in the next version

@acelaya
Copy link
Contributor

acelaya commented Nov 29, 2024

Thanks for taking a look @rschristian!

@rschristian rschristian changed the title Fix/types after preact 10.25 fix: Types after preact 10.25 Nov 29, 2024
@rschristian rschristian marked this pull request as ready for review December 2, 2024 07:56
@rschristian
Copy link
Contributor Author

rschristian commented Dec 2, 2024

@acelaya Preact 10.25.1 is out will all the fixes, should be good to go-ish. You still have an issue with passing an href prop to an element that's annotated as taking HTMLButtonAttributes, and you seemingly don't try to use that href anywhere, so it might just be a mistake? Not quite sure, but that's something I can only guess at the correct fix for. Depends on how you might be using it!

Feel free to make additional edits, copy/paste from here, whatever. And of course ping if you run into any more trouble with the types. We've made a big change in recent versions but hope to get everyone switched over without too much difficulty.

@@ -41,7 +41,7 @@ type ComponentProps = {
};

export type HTMLButtonAttributes = Omit<
JSX.HTMLAttributes<HTMLButtonElement>,
JSX.ButtonHTMLAttributes<HTMLButtonElement>,
Copy link
Contributor

@acelaya acelaya Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just have a question. Are the new JSX.ButtonHTMLAttributes, JSX.InputHTMLAttributes, etc., available in preact versions older than 10.25?

If not, we may need to bump the minimum required preact version of this library, since we ship type definitions with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great question: they've were available from preact/compat since 10.23 but are only available from preact since 10.25.

I see only now there was a peer dependency on preact, sorry! In that case, indeed, you'll probably need a bump.


You might be able to work out a system if you need to keep compat with older versions, though it might require some tooling. Essentially, the HTMLAttributes used here was a mega interface of all possible attributes (across all elements) which has been renamed to AllHTMLAttributes in v10.25+. HTMLAttributes in v10.25+ therefore is the purely global attributes/props, things like class, id, etc. You could probably set up some sort of fallback situation there if you needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Bumping the minimum required version should be fine 🙂

@acelaya
Copy link
Contributor

acelaya commented Dec 2, 2024

Thanks @rschristian! This is much appreciated.

We just realized our workflows are not configured to run on pull requests, but on push only (we usually create PRs here directly), so continuous integration didn't trigger.

I'll clone this locally, fix the href issue, and verify everything works. Then I'll merge this.

@acelaya acelaya force-pushed the fix/types-after-preact-10.25 branch from c300b75 to d6e9226 Compare December 2, 2024 09:01
@@ -60,7 +60,7 @@
"yalc": "^1.0.0-pre.50"
},
"peerDependencies": {
"preact": "^10.4.0"
"preact": "^10.25.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting minimum required version to 10.25.1 rather than 10.25.0, since it includes some important type fixes.

Comment on lines -109 to +111
<LinkButton href="https://www.example.com" underline="hover">
Underline: hover
</LinkButton>
<LinkButton underline="hover">Underline: hover</LinkButton>

<LinkButton href="https://www.example.com" underline="always">
Underline: always
</LinkButton>
<LinkButton underline="always">Underline: always</LinkButton>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The href attribute was not used in LinkButton, so it's safe to remove.

These were probably some old examples from a time in which it may have supported it.

@acelaya acelaya force-pushed the fix/types-after-preact-10.25 branch from d6e9226 to 804fc1d Compare December 2, 2024 09:06
Copy link

codecov bot commented Dec 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (d25366f) to head (804fc1d).
Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1803   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           68        68           
  Lines         1234      1234           
  Branches       468       468           
=========================================
  Hits          1234      1234           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@acelaya acelaya merged commit d88dc6e into hypothesis:main Dec 2, 2024
4 checks passed
@rschristian rschristian deleted the fix/types-after-preact-10.25 branch December 3, 2024 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants